//
//  BZGHSSetViewController.m
//  penzer
//
//  Created by caiyc on 2018/11/15.
//  Copyright © 2018年 caiyc. All rights reserved.
//

#import "BZGHSSetViewController.h"
#import "BZMineRegularItemTableViewCell.h"
#import "BZMineHearView.h"
#import "BZSetTopTableViewCell.h"
#import "BZGHSSetFooterTableViewCell.h"
#import "ChangeRoleViewController.h"
#import "AppDelegate.h"

@interface BZGHSSetViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,copy)NSMutableArray *table_Data;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@end

@implementation BZGHSSetViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"设置";
    [self configData];
    [self SetupTabView];
    // Do any additional setup after loading the view from its nib.
}


-(void)configData
{
    NSArray *subtitle = @[@"代理商",@"",@"159****6207",@"",@""];
    NSArray *titles = @[@"账户角色",@"安全中心",@"手机号",@"求助反馈",@"关于"];
    for(int i =0;i<titles.count;i++){
        BZMineRegualTableModel*model = [BZMineRegualTableModel new];
        model.title = titles[i];
        if(i==1||i==4||i==3){
            model.canClick = 1;
        }else{
            model.canClick = 0;
        }
       
        model.imageStr = @"";
        model.sub_title = subtitle[i];
        model.titleColor = RGBA(51, 51, 51,0.5);
        [self.table_Data addObject:model];
    }
    [self.tableView reloadData];
}



-(void)SetupTabView
{
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([BZMineRegularItemTableViewCell class]) bundle:nil]  forCellReuseIdentifier:NSStringFromClass([BZMineRegularItemTableViewCell class])];
     [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([BZSetTopTableViewCell class]) bundle:nil]  forCellReuseIdentifier:NSStringFromClass([BZSetTopTableViewCell class])];
      [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([BZGHSSetFooterTableViewCell class]) bundle:nil]  forCellReuseIdentifier:NSStringFromClass([BZGHSSetFooterTableViewCell class])];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.estimatedRowHeight = 200;
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
   
}



-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return section==1?self.table_Data.count:1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat height = 0;
    switch (indexPath.section) {
        case 0:{//头像
            height = 110;
            break;
        }
            
        case 1:{//角色、安全中心、手机号、反馈、关于
            height = 64;
            break;
        }
            
        case 2:{//切换身份、退出登录
            height = 164;
            break;
        }
    }
    return height;
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     __weak typeof(self) weakSelf = self;
    switch (indexPath.section) {
        case 0:{//头像
            BZSetTopTableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:NSStringFromClass([BZSetTopTableViewCell class])];
            cell.edit_icon=^(){
                /**编辑用户头像**/
            };
            return cell;
            break;
        }
            
        case 1:{//角色、安全中心、手机号、反馈、关于
            BZMineRegularItemTableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:NSStringFromClass([BZMineRegularItemTableViewCell class])];
            [cell setModel:self.table_Data[indexPath.row]];
            return cell;
            break;
        }
            
        case 2:{//切换身份、退出登录
            BZGHSSetFooterTableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:NSStringFromClass([BZGHSSetFooterTableViewCell class])];
            /**切换角色**/
            cell.role_Action=^(){
                [self changeRole];
            };
            /**退出登录**/
            cell.exit_Action=^(){
                [self loginOut];
            };
            return cell;
            break;
        }
    }
    return nil;
}



- (void)loginOut
{
    [[NSNotificationCenter defaultCenter] postNotificationName:STOPTIMENOTO object:nil];
    [XTool SaveDefaultInfo:nil Key:G_BUSSION_INFO];
    [XTool SaveDefaultInfo:nil Key:Prole];
    [APPDELEGATE goComenLoginWithRoleType:RoleType_GHS targetVc:self];
    
}


- (void)changeRole
{
    ChangeRoleViewController *vc = [[ChangeRoleViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}


#pragma mark--getter&&setter
-(NSMutableArray*)table_Data{
    if(!_table_Data){
        _table_Data = [NSMutableArray array];
    }
    return _table_Data;
}

@end
